/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ez2find.backing;

import com.ez2find.manager.AreaManagerLocal;
import com.ez2find.manager.CountryManagerLocal;
import com.ez2find.model.Area;
import com.ez2find.model.Nick;
import com.ez2find.services.SessionContextLocal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * @author Owner
 */
public class SessionBean {

    @EJB
    private SessionContextLocal ejbSession;
    @EJB
    private AreaManagerLocal ejbAreaManager;
    @EJB
    private CountryManagerLocal ejbCountries;
    private int pagePostsUser;
    private boolean replyMessages;
    private boolean emailMessages;
    private boolean flagMessages;
    private boolean topic;
    private Integer treeForum;
    private Nick nick;
    private int pageSites;
    
    public SessionContextLocal getEjbSession() {
        return ejbSession;
    }

    public void setEjbSession(SessionContextLocal ejbSession) {
        this.ejbSession = ejbSession;
    }

    public List<Area> getAreasCurrentSite() {
        return ejbAreaManager.areasSite(ejbSession.getCurrentSite());
    }

    public int getPagePostsUser() {
        return pagePostsUser;
    }

    public void setPagePostsUser(int pagePostsUser) {
        this.pagePostsUser = pagePostsUser;
    }

    public boolean isReplyMessages() {

        return replyMessages;
    }

    public void setReplyMessages(boolean replyMessages) {
        this.replyMessages = replyMessages;
    }

    public Integer getTreeForum() {
        return treeForum;
    }

    public void setTreeForum(Integer treeForum) {
        this.treeForum = treeForum;
    }

    public boolean isEmailMessages() {
        return emailMessages;
    }

    public void setEmailMessages(boolean emailMessages) {
        this.emailMessages = emailMessages;
    }

    public boolean isTopic() {
        return topic;
    }

    public void setTopic(boolean topic) {
        this.topic = topic;
    }

    public List<Nick> getNicks() {
        if (ejbSession.getOwner() == null) {
            List<Nick> aux = new ArrayList<Nick>();
            return aux;
        }
        return ejbSession.getOwner().getNicks();
    }

    public boolean getTooManyHandles() {
        boolean ans = false;
        if (getNicks().size() > 5) {
            ans = true;
        }
        return ans;
    }

    public Nick getNick() {
        return nick;
    }

    public void setNick(Nick nick) {
        this.nick = nick;
    }

    public int getPageSites() {
        return pageSites;
    }

    public void setPageSites(int pageSites) {
        this.pageSites = pageSites;
    }

    public boolean isFlagMessages() {
        return flagMessages;
    }

    public void setFlagMessages(boolean flagMessages) {
        this.flagMessages = flagMessages;
    }

    public boolean getAccountHandle() {
        boolean ans = false;
        if ((getEjbSession().getOwner() != null) && (!getEjbSession().getOwner().getHandles().isEmpty())) {
            ans = true;
        }
        return ans;
    }

    public void setCountryId(long countryId) {
        getEjbSession().setCurrentSite(ejbCountries.find(countryId).getSites().get(0));
    }
    
}
